package com.cha.chaApp.sys.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cha.chaApp.sys.goods.service.GoodsService;
import com.cha.chaApp.sys.order.param.CreateShopParam;
import com.cha.chaApp.sys.order.service.OrderService;
import com.cha.chaApp.sys.order.service.ShopCarService;
import com.cha.chaApp.sys.order.vo.OrderVO;
import com.cha.chaApp.sys.order.vo.ShopCarVO;
import com.cha.chaCommon.core.common.PageParam;
import com.cha.chaCommon.core.common.R;
import com.cha.chaCommon.core.entity.hkf.Goods;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/*
@Author  hkf
@date 2024/11/12
--轻舟已过万重山--
*/
@RestController
@Api(tags = "购物管理")
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;
    @Resource
    private ShopCarService shopCarService;

    @Resource
    private GoodsService goodsService;
    @PostMapping("/create")
    @ApiOperation(value = "生成定单", notes = "生成定单")
    public R create(@RequestBody CreateShopParam param){
        orderService.createOrder(param);
        return R.ok();
    }
    @GetMapping("/getGoods")
    @ApiOperation(value = "分页显示所有商品", notes = "分页显示所有商品")
    public R getGoods(PageParam param){
        Page<Goods> goods = goodsService.goodsAllInfo(param);
        return R.ok(goods);
    }
    @GetMapping("/nopay")
    @ApiOperation(value = "分页显示未支付状态商品", notes = "分页显示未支付状态商品")
    public R noPay(PageParam param){
        Page<OrderVO> orders = orderService.noPay(param);
        return R.ok(orders);
    }
    @GetMapping("/prepareSend")
    @ApiOperation(value = "分页显示代发货商品", notes = "分页显示代发货商品")
    public R prepareSend(PageParam param){
        Page<OrderVO> orders = orderService.prepareSend(param);
        return R.ok(orders);
    }
    @GetMapping("/beforeReceive")
    @ApiOperation(value = "分页显示待收货商品", notes = "分页显示待收货商品")
    public R beforeReceive(PageParam param){
        Page<OrderVO> orders = orderService.beforeReceive(param);
        return R.ok(orders);
    }
    @GetMapping("/prepareComment")
    @ApiOperation(value = "分页显示待评价商品", notes = "分页显示待评价商品")
    public R prepareComment(PageParam param){
        Page<OrderVO> orders = orderService.prepareComment(param);
        return R.ok(orders);
    }
    @PostMapping("/createShopCar")
    @ApiOperation(value = "加入购物车", notes = "加入购物车")
    public R createShopCar(@RequestBody List<CreateShopParam> params){
        shopCarService.createShopCar(params);
        return R.ok();
    }
    @PostMapping("/showShopCar")
    @ApiOperation(value = "查询购物车", notes = "查询购物车")
    public R showShopCar(PageParam param){
        Page<ShopCarVO> shopCarVOS = shopCarService.shopCarVOInfo(param);
        return R.ok(shopCarVOS);
    }
    @PostMapping("/shopCarToNoPay")
    @ApiOperation(value = "购物车一键结算", notes = "购物车一键结算")
    public R shopCarToNoPay(){
        orderService.updateShopCar();
        return R.ok();
    }
}
